package com.vains.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.vains.entity.OauthPermission;
import com.vains.entity.customer.OAuthPermissionCustomer;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * <p>
 * 资源表 Mapper 接口
 * </p>
 *
 * @author vains
 * @since 2020-06-08
 */
public interface OauthPermissionMapper extends BaseMapper<OauthPermission> {

    /**
     * 获取所有未删除的资源
     * @return 所有未删除的资源 带有父节点名称
     * @param page 分页帮助
     */
    @Select("SELECT t1.*, IFNULL(t2.permission_name, '父节点') AS parent_permission_name FROM oauth_permission t1 LEFT JOIN oauth_permission t2 ON t1.permission_parent_id = t2.permission_id WHERE t1.permission_deleted = 0")
    List<OAuthPermissionCustomer> getAllPermissions(Page<OauthPermission> page);

}
